package com.djzhou.gmms.log.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.djzhou.gmms.base.action.BaseAction;
import com.djzhou.gmms.model.authority.TbAuthority;
import com.djzhou.gmms.model.log.TbLog;
import com.djzhou.gmms.util.session.UserSession;

public class LogAction extends BaseAction<TbLog> {


	private List<TbLog> list;
	private Integer logId;
	private TbLog log;
	
	private String menuName;
	private String loginName;
	private String startDate;
	private String endDate;
	private String recordId;
	
	@Override
	public String delete() {
		logService.delete(logId);
		msg="删除成功";
		setCurrentPage(currentPage);
		return SUCCESS;
	}
	

	@Override
	public String toEdit() {
		
		return SUCCESS;
	}

	
	@Override
	public String queryList() {
		if(loadData==null)return SUCCESS;
		HashMap<String, Object> hashMap=new HashMap<String, Object>();
		//筛除超级管理员
		if(queryRoleIds4Page().indexOf(",1,")!=-1){
			//加入层级权限 将公司层级权限编码加入
			hashMap.put("companyId", UserSession.getSessionModel().getChildCompanyIds()+queryCompany().getCompanyId());
			hashMap.put("departmentId", UserSession.getSessionModel().getChildDepartmentIds()+queryDepartment().getDepartmentId());
		}
		
		if(menuName!=null && !menuName.equals(""))hashMap.put("menuName", menuName);
		if(loginName!=null && !loginName.equals(""))hashMap.put("loginName", loginName);
		if(startDate!=null && !startDate.equals(""))hashMap.put("startDate", startDate);
		if(endDate!=null && !endDate.equals(""))hashMap.put("endDate", endDate);
		if(recordId!=null && !endDate.equals(""))hashMap.put("recordId", recordId);
		
		pageBean=logService.queryPageBean(hashMap, pageSize, currentPage);
		list=pageBean.getList();
		if(currentPage>1){
			if(list==null || list.size()==0){
				setCurrentPage(getCurrentPage()-1);
				pageBean=logService.queryPageBean(hashMap, pageSize, currentPage);
				list=pageBean.getList();
			}
		}
		if(list!=null){
			totalCount=pageBean.getAllRow();
		}else{
			totalCount = 0;
			list = new ArrayList<TbLog>();
		}
		totalPage=pageBean.getTotalPage();
		setMenuName(menuName);
		setLoginName(loginName);
		setStartDate(startDate);
		setEndDate(endDate);
		return SUCCESS;
	}

	public List<TbLog> getList() {
		return list;
	}

	public void setList(List<TbLog> list) {
		this.list = list;
	}

	public Integer getLogId() {
		return logId;
	}

	public void setLogId(Integer logId) {
		this.logId = logId;
	}

	public TbLog getLog() {
		return log;
	}

	public void setLog(TbLog log) {
		this.log = log;
	}


	public String getMenuName() {
		return menuName;
	}


	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}


	public String getLoginName() {
		return loginName;
	}


	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}


	public String getStartDate() {
		return startDate;
	}


	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}


	public String getEndDate() {
		return endDate;
	}


	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}


	public String getRecordId() {
		return recordId;
	}


	public void setRecordId(String recordId) {
		this.recordId = recordId;
	}
	
	
	
}
